package code.rocky.week.s103;

import java.util.Arrays;

public class MaximizeSum {

    public int maximizeSum(int[] nums, int k) {
        if (k == 0) return 0;
        Arrays.sort(nums);
        return  nums[nums.length-1] * k + addNum(k);
    }

    private int addNum(int k) {
        if (k == 0) {
            return 0;
        }
        int n = 0;
        while (k > 0) {
            k = k -1;
            n+=k;
        }
        return n;
    }


    public static void main(String[] args) {
        int[] num = new int[]{1,2,3,4,5};
        int[] num1 = new int[]{5,5,5};
        int[] num2 = new int[]{4,4,9,10,10,9,3,8,4,2,5,3,8,6,1,10,4,5,3,2,3,9,5,7,10,4,9,10,1,10,4};
        MaximizeSum maximizeSum = new MaximizeSum();
        System.out.println(maximizeSum.maximizeSum(num2, 6));
    }
}
